public class TestDemo2 {

    //reverse
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("abcdef");
        sb.reverse();
        System.out.println(sb);
        StringBuffer sb2 = new StringBuffer();
        sb2.reverse();
        String str = "abcdef";
    }

    //这个正确
    public static void main3(String[] args) {
        String str = "abcdef";
        StringBuilder sb = new StringBuilder();
        sb.append(str);
        for (int i = 0; i < 10; i++) {
            sb.append(i);
        }
        str = sb.toString();
        System.out.println(str);
    }

    //这个有问题
    public static void main2(String[] args) {
        String str = "abcdef";
        for (int i = 0; i < 10; i++) {
            StringBuilder sb = new StringBuilder();
            sb.append(str).append(i);
            str = sb.toString();
        }
        System.out.println(str);
    }

    //字符串的 "+" 相当于 stringbuilder 的 append
    public static void main1(String[] args) {
        //String str = "abcdef";
        StringBuilder sb = new StringBuilder();
        sb.append("abcdef");
        //str += "123";//str = str + "123"
        sb.append("123");
        //str = sb.toString();
        System.out.println(sb);
    }

}